using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class FlashLightController : MonoBehaviour
{
    public Transform player;
    public PlayerInputController playerInputController;
    public Vector2 PositionOffset;
    public float rotationDamping;

    void Update()
    {
        transform.position = player.position+(Vector3)PositionOffset;
       

        // 计算鼠标位置与玩家位置的方向向量
        Vector3 direction = playerInputController.GetMousePosition() - player.position;

        // 计算角度（弧度），并转换为度数
        float targetAngle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;

        // 计算目标旋转
        Quaternion targetRotation = Quaternion.Euler(0, 0, targetAngle);

        // 计算当前旋转和目标旋转的差异
        float angleDifference = Quaternion.Angle(transform.rotation, targetRotation);

        // 如果旋转差异小于180度，执行阻尼过渡
        if (angleDifference < 180)
        {
            // 执行平滑旋转
            transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.deltaTime * rotationDamping);
        }
        else
        {
            // 如果旋转差异接近180度，跳过平滑过渡，直接设置目标旋转
            transform.rotation = targetRotation;
        }
    }
    
}
